package com.kandinfo.base.common.controller;

import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kandinfo.base.common.xmemcached.ShiroMemcachedManager;
import com.kandinfo.base.security.util.RoleConstants;

@Controller
@RequestMapping(value = "/__super__admin~~")
public class SuperAdminController {
	@Autowired
	private CacheManager cacheManager;
	@Autowired 
	private	ShiroMemcachedManager shiroMemcachedManager;
	@RequestMapping("/__$clear__cache")
	@RequiresRoles(value=RoleConstants.SUPER_ADMIN)
	@ResponseBody
	public String clearCache(String cacheName){
		cacheManager.getCache(cacheName).clear();
		return "ok";
	}
	@RequestMapping("/__$clear_shiro__cache")
	@RequiresRoles(value=RoleConstants.SUPER_ADMIN)
	@ResponseBody
	public String clearAuthCache(){
		shiroMemcachedManager.clear();
		return "ok";
	}
	@RequestMapping("/__$clear_all__cache")
	@RequiresRoles(value=RoleConstants.SUPER_ADMIN)
	@ResponseBody
	public String clearALLCache(){
		for (String cacheName : cacheManager.getCacheNames()) {
			cacheManager.getCache(cacheName).clear();
		}
		return "ok";
	}
	
	
	
	
}
